﻿using System;
using OpenNETCF.Desktop.Communication;

namespace AMS.Inventory.PCClient.InventoryHelpClass
{
    class PDAFileControl
    {
        //声明 RAPI 对象的实例
        RAPI myrapi;


        public PDAFileControl()
        {

        }

        ~PDAFileControl()
        {
            myrapi = null;
        }

        //连接到设备
        public bool ConnectToPDA()
        {
            try
            {

                myrapi = new RAPI();

                if (myrapi.DevicePresent == false)
                {
                    return false;
                }

                myrapi.Connect();

                bool bConnect = myrapi.DevicePresent;

                return bConnect;

            }

            catch (Exception ex)
            {
                return false;
            }
        }

        //断开与 PDA 连接
        public bool DisConnectToPDA()
        {
            try
            {
                myrapi.Disconnect();
                myrapi.Dispose();

                return true;

            }

            catch (Exception ex)
            {
                return false;
            }
        }


        //检查 PDA 文件是否存在
        public bool PDAFileExists(string sPDAPath)
        {
            try
            {
                bool bExists = myrapi.DeviceFileExists(sPDAPath);

                return bExists;
            }
            catch (Exception ex)
            {
                return false;
            }
        }


        //从PC 拷贝文件到 PDA
        public bool CopyFileToPDA(string sFileSourcePath, string sFileTargetPath)
        {
            try
            {
                myrapi.CopyFileToDevice(sFileSourcePath, sFileTargetPath, true);

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }


        //从PDA 拷贝文件到 PC 
        public bool CopyFileFromPDA(string sFileSourcePath, string sFileTargetPath)
        {
            try
            {
                myrapi.CopyFileFromDevice(sFileTargetPath, sFileSourcePath, true);

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        //PDA 删除文件
        public bool DeletePDAFile(string sPDAFilePath)
        {
            try
            {
                myrapi.DeleteDeviceFile(sPDAFilePath);

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

    }
}